package com.pine.admin.util;

import com.solidfire.gson.Gson;
import com.pine.common.utils.EncodingTool;
import com.sun.tools.hat.internal.model.Root;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class PostUtil {

    public static String send(String orgId) throws Exception {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd%HH:mm:ss");

        Calendar calendar = Calendar.getInstance();

        calendar.add(Calendar.MINUTE, 3);
        //Appkey
        String  url_A_x ="http://api.open.zhaopin.com/platform/org/get?access_token=551c619ef13c45debe92a64880f5e1cdlzJv&orgid="+orgId;

//        String json_send_sms = "{\"display_call\":\"" + display_cal + "}" ;

        URL url = new URL(url_A_x);
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();

        httpURLConnection.setRequestMethod("GET");

        httpURLConnection.setDoOutput(true);

        httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        OutputStream out = httpURLConnection.getOutputStream();

//        out.write(json_send_sms.getBytes("UTF-8"));

        InputStream inputStream = null;
        InputStreamReader inputStreamReader = null;
        BufferedReader reader = null;
        StringBuffer resultBuffer = new StringBuffer();
        String tempLine = null;
        try {
            inputStream = httpURLConnection.getInputStream();
            inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
            reader = new BufferedReader(inputStreamReader);
            while ((tempLine = reader.readLine()) != null) {
                resultBuffer.append(tempLine);
            }
            System.out.println("recv msg:\t"+EncodingTool.UnicodeToUtf8(resultBuffer.toString()));
            return EncodingTool.UnicodeToUtf8(resultBuffer.toString());
        } catch (Exception e) {
            throw e;
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (inputStreamReader != null) {
                inputStreamReader.close();
            }
            if (inputStream != null) {
                inputStream.close();
            }
            httpURLConnection.disconnect();
        }

    }

//    public static void main(String[] args) throws Exception {
//
//
//        String string = PostUtil.send("1");
//        Gson gson = new Gson();
//        Root root = gson.fromJson(string,Root.class);
//    }
}
